//
//  YCEntryPayHeadInfoView.m
//  YCSchool
//
//  Created by gmall on 16/5/3.
//  Copyright © 2016年 yanglinxia. All rights reserved.
//  报名费支付头部

#import "YCEntryPayHeadInfoView.h"

@interface YCEntryPayHeadInfoView ()

/** 学员姓名 */
@property (nonatomic, weak) UILabel *nameLabel;
/** 手机号码 */
@property (nonatomic, weak) UILabel *phoneLabel;
/** 联系地址  */
@property (nonatomic, weak) UILabel *addressLabel;
/** 身份证号码  */
@property (nonatomic, weak) UILabel *idCardNumLabel;
/** 驾驶车型  */
@property (nonatomic, weak) UILabel *carStyleLabel;
/** 所在班级  */
@property (nonatomic, weak) UILabel *classLabel;
/** 训练时间  */
@property (nonatomic, weak) UILabel *trainTimeLabel;


/** 头部与下面tableviewcell的分隔线  */
@property (nonatomic, weak) UIView *line;

@end

@implementation YCEntryPayHeadInfoView

+ (BOOL)requiresConstraintBasedLayout
{
    return YES;
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // 背景颜色容器
        UIView *bgView = [[UIView alloc] init];
        bgView.backgroundColor = [UIColor yc_colorWithUInt:0xfffbf6];
        bgView.layer.borderWidth = 1.0;
        bgView.layer.borderColor = [UIColor yc_colorWithUInt:0xf1f1f1].CGColor;
        [self addSubview:bgView];
        [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.equalTo(self).offset(widthFromIphone6Width(15));
            make.right.equalTo(self).offset(-widthFromIphone6Width(15));
        }];
        
        // 朝右U图片
        UIImageView *arrowImageView = [[UIImageView alloc] init];
        [arrowImageView setImage:[UIImage imageNamed:@"回形针"]];
        arrowImageView.contentMode = UIViewContentModeRight;
        [self addSubview:arrowImageView];
        
        [arrowImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self).offset(heightFromIphone6Height(55));
            make.right.equalTo(self);
            make.width.equalTo(@31);//62x36
            make.height.equalTo(@18);
        }];
        
        // 文字统一字体大小与颜色
        UIColor *textColor = [UIColor darkGrayColor];
        UIFont *font = [UIFont systemFontOfSize:13];
        CGFloat margin = widthFromIphone6Width(13);
        /********************  子控件 *********************/
        // 学员
        UILabel *studentLabel = [[UILabel alloc] init];
        studentLabel.text = @"学员";
        studentLabel.font = font;
        studentLabel.textColor = textColor;
        [bgView addSubview:studentLabel];
        [studentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.equalTo(bgView).offset(margin);
            
        }];
        
        // 姓名
        UILabel *nameLabel = [[UILabel alloc] init];
        nameLabel.text = @"张行";
        nameLabel.font = font;
        nameLabel.textColor = textColor;
        [bgView addSubview:nameLabel];
        self.nameLabel = nameLabel;
        [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.bottom.equalTo(studentLabel);
            make.left.equalTo(bgView).offset(widthFromIphone6Width(118));
            make.right.equalTo(bgView).offset(-margin);
        }];
        
        // 手机号码
        UILabel *phoneNumLabel = [[UILabel alloc] init];
        phoneNumLabel.text = @"手机号码";
        phoneNumLabel.font = font;
        phoneNumLabel.textColor = textColor;
        [phoneNumLabel sizeToFit];
        [bgView addSubview:phoneNumLabel];
        [phoneNumLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(studentLabel.mas_bottom).offset(heightFromIphone6Height(15));
            make.left.equalTo(studentLabel);
        }];
        
        // 号码
        UILabel *phoneLabel = [[UILabel alloc] init];
        phoneLabel.text = @"18028019944";
        phoneLabel.font = font;
        phoneLabel.textColor = textColor;
        [phoneLabel sizeToFit];
        [bgView addSubview:phoneLabel];
        self.phoneLabel = phoneLabel;
        [phoneLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.bottom.equalTo(phoneNumLabel);
            make.left.equalTo(bgView).offset(widthFromIphone6Width(118));
            make.right.equalTo(bgView).offset(-margin);
        }];
        
        // 联系地址
        UILabel *contactLabel = [[UILabel alloc] init];
        contactLabel.text = @"联系地址";
        contactLabel.font = font;
        contactLabel.textColor = textColor;
        [bgView addSubview:contactLabel];
        [contactLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(phoneNumLabel.mas_bottom).offset(heightFromIphone6Height(15));
            make.left.equalTo(phoneNumLabel);
        }];
        
        // 地址
        UILabel *addressLabel = [[UILabel alloc] init];
        addressLabel.text = @"广州市天河区珠江新城金穗路3号汇美大厦1603";
        addressLabel.font = font;
        addressLabel.textColor = textColor;
        addressLabel.numberOfLines = 0;
        [addressLabel sizeToFit];
        [bgView addSubview:addressLabel];
        self.addressLabel = addressLabel;
        [addressLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(contactLabel);
            make.left.equalTo(bgView).offset(widthFromIphone6Width(118));
            make.right.equalTo(bgView).offset(-margin);
        }];
        
        // 身份证号码
        UILabel *idCardLabel = [[UILabel alloc] init];
        idCardLabel.text = @"身份证号码";
        idCardLabel.font = font;
        idCardLabel.textColor = textColor;
        [bgView addSubview:idCardLabel];
        [idCardLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(addressLabel.mas_bottom).offset(heightFromIphone6Height(15));
            make.left.equalTo(contactLabel);
        }];
        
        // 身份号码
        UILabel *idCardNumLabel = [[UILabel alloc] init];
        idCardNumLabel.text = @"230107199001191018";
        idCardNumLabel.font = font;
        idCardNumLabel.textColor = textColor;
        idCardNumLabel.numberOfLines = 0;
        [bgView addSubview:idCardNumLabel];
        self.idCardNumLabel = idCardNumLabel;
        [idCardNumLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(idCardLabel);
            make.left.equalTo(bgView).offset(widthFromIphone6Width(118));
            make.right.equalTo(bgView).offset(-margin);
        }];
        
        // 驾驶车型
        UILabel *carLabel = [[UILabel alloc] init];
        carLabel.text = @"驾驶车型";
        carLabel.font = font;
        carLabel.textColor = textColor;
        [bgView addSubview:carLabel];
        [carLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(idCardNumLabel.mas_bottom).offset(heightFromIphone6Height(15));
            make.left.equalTo(idCardLabel);
        }];
        
        // 车型
        UILabel *carStyleLabel = [[UILabel alloc] init];
        carStyleLabel.text = @"小型车(C1/C2)";
        carStyleLabel.font = font;
        carStyleLabel.textColor = textColor;
        [bgView addSubview:carStyleLabel];
        self.carStyleLabel = carStyleLabel;
        [carStyleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(carLabel);
            make.left.equalTo(bgView).offset(widthFromIphone6Width(118));
            make.right.equalTo(bgView).offset(-margin);
        }];
        
        // 所在班级
        UILabel *locClassLabel = [[UILabel alloc] init];
        locClassLabel.text = @"所在班级";
        locClassLabel.font = font;
        locClassLabel.textColor = textColor;
        [bgView addSubview:locClassLabel];
        [locClassLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(carLabel.mas_bottom).offset(heightFromIphone6Height(15));
            make.left.equalTo(carLabel);
        }];
        
        // 班级--vip班
        UILabel *classLabel = [[UILabel alloc] init];
        classLabel.text = @"VIP班";
        classLabel.font = font;
        classLabel.textColor = [UIColor redColor];
        [bgView addSubview:classLabel];
        self.classLabel = classLabel;
        [classLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(locClassLabel);
            make.left.equalTo(bgView).offset(widthFromIphone6Width(118));
            make.right.equalTo(bgView).offset(-margin);
        }];
        
        // 训练时间
        UILabel *timeLabel = [[UILabel alloc] init];
        timeLabel.text = @"训练时间";
        timeLabel.font = font;
        timeLabel.textColor = textColor;
        [bgView addSubview:timeLabel];
        [timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(locClassLabel.mas_bottom).offset(heightFromIphone6Height(15));
            make.left.equalTo(locClassLabel);
        }];
        
        // 时间--周末全天
        UILabel *trainTimeLabel = [[UILabel alloc] init];
        trainTimeLabel.text = @"周末全天";
        trainTimeLabel.font = font;
        trainTimeLabel.textColor = textColor;
        [bgView addSubview:trainTimeLabel];
        self.trainTimeLabel = trainTimeLabel;
        [trainTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(timeLabel);
            make.left.equalTo(bgView).offset(widthFromIphone6Width(118));
            make.right.equalTo(bgView).offset(-margin);
        }];
        
        // 更容背影view大小
        [bgView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(trainTimeLabel.mas_bottom).offset(margin * 2);//30左右
        }];
        
        /// 添加选择支付方式label
        UILabel *payMethodLabel = [[UILabel alloc] init];
        payMethodLabel.text = @"选择支付方式";
        payMethodLabel.font = [UIFont systemFontOfSize:15];
        payMethodLabel.textColor = [UIColor redColor];
        [self addSubview:payMethodLabel];
        [payMethodLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(bgView.mas_bottom).offset(widthFromIphone6Width(44));
            make.left.equalTo(self).offset(widthFromIphone6Width(21));
        }];
        
        // 分隔线
        UIView *line = [[UIView alloc] init];
        line.backgroundColor = [UIColor colorWithWhite:0.2 alpha:0.2];
        [self addSubview:line];
        self.line = line;
        [line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(payMethodLabel.mas_bottom).offset(2);
            make.height.equalTo(@1);
            make.left.right.equalTo(self);
        }];
        
        [self mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(line);
        }];
        
    }
    return self;
}


- (void)setModel:(YCFillInfomationModel *)model
{
    _model = model;
    self.nameLabel.text         = model.ycname;
    self.phoneLabel.text        = model.ycmobile;
    self.addressLabel.text      = model.ycaddress;
    self.idCardNumLabel.text    = model.ycidcard;
    self.carStyleLabel.text     = model.cartypeName;
    self.classLabel.text        = model.classtypeName;
    self.trainTimeLabel.text    = model.periodidName;
    if ([model.classtypeName isEqualToString:@"vip班"]) {
        self.classLabel.textColor = [UIColor redColor];
    } else {
        self.classLabel.textColor = [UIColor darkGrayColor];
    }
}

@end
